package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.domain.UserInfo;
import com.tanhua.model.vo.PageResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Description: test
 * @Create by: JJ菜菜
 * @Date: 2021/12/8 23:51
 */

@RestController
@RequestMapping("/manage")
public class ManageController {

    @Autowired
    private ManagerService managerService;

    /**
     * 查看用户列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize) {
        PageResultVo result = managerService.findAllUsers(page, pagesize);
        return ResponseEntity.ok(result);
    }

    /**
     * 根据id查询数据详情
     *
     * @param usersId
     * @return
     */
    @GetMapping("/users/{userID}")
    public ResponseEntity findUserInfoById(@PathVariable("userID") Long usersId) {

        UserInfo userInfo = managerService.findUserInfoById(usersId);
        return ResponseEntity.ok(userInfo);
    }


    /**
     * 查询指定用户发布的所有视频列表
     */
    @GetMapping("/videos")
    public ResponseEntity videos(@RequestParam(defaultValue = "1") Integer page,
                                 @RequestParam(defaultValue = "10") Integer pagesize,
                                 Long uid) {

        PageResultVo result = managerService.findAllVideos(page, pagesize, uid);
        return ResponseEntity.ok(result);
    }


    //查询动态
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid, Integer state) {
        PageResultVo result = managerService.findAllMovements(page, pagesize, uid, state);
        return ResponseEntity.ok(result);
    }


    /**
     * 用户冻结
     * @param params
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map params) {
        Map map =  managerService.userFreeze(params);
        return ResponseEntity.ok(map);
    }

    //用户解冻
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody  Map params) {

        Map map =  managerService.userUnfreeze(params);
        return ResponseEntity.ok(map);
    }

}
